import mysql.connector

# 连接数据库
conn = mysql.connector.connect(
    host='47.94.130.233',
    user='root',
    passwd='123456',
    auth_plugin='mysql_native_password',
    database='training'
)
# print(conn)
# 获取游标
my_cursor = conn.cursor()
# 准备SQL
sql = 'update emp set nickname = %s where id = %s'
# 准备插入的数据
values = ('徐晓羽', 2)

try:
    # 执行SQL
    my_cursor.execute(sql, values)
    # 手动提交事务
    conn.commit()
    print('修改了', my_cursor.rowcount, '条数据')
except Exception as e:
    # 事务回滚
    conn.rollback()
finally:
    # 关闭连接
    conn.close()
